package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Filter {

    List<Integer>  array;

    public Filter(List<Integer> array) {

        this.array = array;
    }

    public List<Integer> filterEven() {
        //求数组中的偶数
        return array.stream().filter(this::isEven).collect(Collectors.toList());
        // throw new NotImplementedException();
        }

    private boolean isEven(int num) {
        return num % 2 == 0;

    }

    public List<Integer> filterMultipleOfThree() {
        //求数组中3的倍数
        return array.stream().filter(this::isTripleNum).collect(Collectors.toList());
     //   throw new NotImplementedException();
    }
    private boolean isTripleNum(int num){
        return num % 3 == 0;
    }

    public List<Integer> getCommonElements(List<Integer> firstList, List<Integer> secondList) {
        //去除数组中的重复元素
        // distinct（）返回由该流的不同元素组成的流
        return array.stream().distinct().collect(Collectors.toList());
     //   throw new NotImplementedException();
    }

    public List<Integer> getDifferentElements(List<Integer> firstList, List<Integer> secondList) {
        //求两数组的公共元素
        return firstList.stream().filter(secondList::contains).collect(Collectors.toList());
     //   throw new NotImplementedException();
    }
}